package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;



/*
 * 
 *  使用hystrix保护应用
 *  	断路器模式
 * 		1.添加maven包
 * 		2.在启动类上添加@EnableCircuitBreaker
 * 		3.在方法上面添加@HystrixCommand(fallbackMethod="findByIdFallback")
 * 		4.创建一个方法findByIdFallback，注意参数和前面的方法,返回值要一致
 * 		5.在访问http://localhost:8010/hystrix.stream，必须先访问http://localhost:8010/movie/1,在浏览器两个同时连接访问
 * 		
 * 
 * 
 * */

@EnableCircuitBreaker
@EnableEurekaClient
@SpringBootApplication
public class SimpleRibbonHystrixApplication {
	
	@Bean
	@LoadBalanced
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}
	
	public static void main(String[] args) {
		SpringApplication.run(SimpleRibbonHystrixApplication.class, args);
	}
}
